<template>
  <div class="user-container">
    <div class="user-card">
      <van-cell>
        <!-- 使用 title 插槽来自定义标题 -->
        <template #icon>
          <img :src="userInfo.photo" alt="" class="avatar" />
        </template>
        <template #title>
          <span class="username">{{ userInfo.name }}</span>
        </template>
        <template #label>
          <van-tag round size="large" color="#fff" text-color="#007bff"
            >申请认证</van-tag
          >
        </template>
      </van-cell>
      <div class="user-data">
        <div class="user-data-item">
          <span>{{ userInfo.art_count }}</span>
          <span>动态</span>
        </div>
        <div class="user-data-item">
          <span>{{ userInfo.follow_count }}</span>
          <span>关注</span>
        </div>
        <div class="user-data-item">
          <span>{{ userInfo.fans_count }}</span>
          <span>粉丝</span>
        </div>
      </div>
    </div>

    <van-cell-group class="action-card">
      <van-cell
        icon="edit"
        title="编辑资料"
        is-link
        @click="$router.push({ name: 'useredit' })"
      />
      <van-cell icon="chat-o" title="小思同学" is-link to="/chat" />
      <van-cell icon="warning-o" title="退出登录" is-link @click="logout" />
    </van-cell-group>
  </div>
</template>

<script>
// import { getUserInfoAPI } from '@/api/userAPI'
import { mapActions, mapState } from 'vuex'
export default {
  data() {
    return {}
  },

  components: {},

  computed: {
    ...mapState(['userInfo']),
    userInfo1() {
      return this.$store.getters.userInfo1
    }
  },
  created() {
    // this.getUserInfo()
    // this.$store.dispatch('initUserInfo')
    this.initUserInfo()
  },

  mounted() {},

  methods: {
    ...mapActions(['initUserInfo']),
    logout() {
      this.$store.commit('cleanLocalData')
      this.$router.push('/login')
    }
    // async getUserInfo() {
    //   const { data: res } = await getUserInfoAPI()
    //   console.log('res:', res)
    // }
  }
}
</script>
<style lang="less" scoped>
.user-container {
  width: 750px;
  .user-card {
    background-color: #007bff;
    color: white;
    padding-top: 40px;
    .van-cell {
      background: #007bff;
      color: white;
      &::after {
        display: none;
      }
      .avatar {
        width: 120px;
        height: 120px;
        background-color: #fff;
        border-radius: 50%;
        margin-right: 20px;
      }
      .username {
        font-size: 28px;
        font-weight: bold;
      }
    }
  }
  .user-data {
    display: flex;
    justify-content: space-evenly;
    align-items: center;
    font-size: 28px;
    padding: 60px 0;
    .user-data-item {
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      width: 33.33%;
    }
  }
}
</style>
